package com.bq.gametrade.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.base.BaseActivity;
import com.bq.gametrade.utils.NetworkUtils;
import com.bq.gametrade.view.TimeButton;

public class PerfectAccountActivity extends BaseActivity implements View.OnClickListener{

    private ImageView back;
    private TextView tvTitle;
    private EditText edtAccount,etPassword,etConfirmPassword,etVerificationCode;
    private String phoneNumber;
    private TextView tvGetCode,tvPhoneNumber;
    private Button btnNext;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_perfectaccount);
        phoneNumber = getIntent().getStringExtra("phoneNumber");
        initView();
    }


    private void initView() {
        back = serchViewById(R.id.image_back);
        back.setOnClickListener(this);
        tvTitle = serchViewById(R.id.title_name);
        tvTitle.setText("完善信息");

        tvPhoneNumber = serchViewById(R.id.tv_phoneNumber);
        StringBuilder msg = new StringBuilder().append(phoneNumber.substring(0, 3))
                .append("****").append(phoneNumber.substring(7));
        tvPhoneNumber.setText(msg);

        edtAccount = serchViewById(R.id.et_userAccount);
        etPassword = serchViewById(R.id.et_password);
        etConfirmPassword = serchViewById(R.id.et_confirmPassword);
        etVerificationCode = serchViewById(R.id.et_verificationCode);

        tvGetCode = serchViewById(R.id.tv_getCode);
        tvGetCode.setOnClickListener(this);
        btnNext = serchViewById(R.id.btn_complete);
        btnNext.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_back:
                finish();
                break;
            case R.id.tv_getCode:
                TimeButton timeButton = new TimeButton(PerfectAccountActivity.this,10*1000, 1000,tvGetCode);
                timeButton.start();
                break;
            case R.id.btn_complete:
                if(TextUtils.isEmpty(edtAccount.getText().toString())){
                    toastShow("用户名没有输入");
                    return;
                }
                if(edtAccount.getText().toString().length()<5){
                    toastShow("用户名不能少于5位");
                    return;
                }
                if(edtAccount.getText().toString().length()>20){
                    toastShow("用户名不能多余20位");
                    return;
                }
                if(TextUtils.isEmpty(etPassword.getText().toString())){
                    toastShow("密码没有输入");
                    return;
                }
                if(etPassword.getText().toString().length()<6){
                    toastShow("密码不能少于6位");
                    return;
                }
                if(etPassword.getText().toString().length()>20){
                    toastShow("密码不能多余20位");
                    return;
                }
                if(!etPassword.getText().toString().equals(etConfirmPassword.getText().toString())){
                    toastShow("两次密码输入不一样");
                    return;
                }
                if(TextUtils.isEmpty(etVerificationCode.getText().toString())){
                    toastShow("验证码没有输入");
                    return;
                }
                if(NetworkUtils.isNetworkAvailable(PerfectAccountActivity.this)){
                    toastShow("正在提交·····");
                }else {
                    toastShow("检查网络");
                }
                break;
        }
    }
}
